//
//  CostCell.m
//  MyStock
//
//  Created by 刘翔 on 2024/12/12.
//

#import "CostCell.h"

@implementation CostCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _tagView.alignment = TTGTagCollectionAlignmentLeft;
    _tagView.manualCalculateHeight = YES;
    _tagView.userInteractionEnabled = YES;
    _tagView.delegate =self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setTags:(NSArray <NSString *> *)tags withSeleted:(NSString *)seletedTag {
    [_tagView removeAllTags];

    NSMutableArray *textTags = [NSMutableArray new];
    for (NSString *string in tags) {
        
        TTGTextTagStyle *style = [TTGTextTagStyle new];
        style.extraSpace = CGSizeMake(5, 5);
        style.backgroundColor = [UIColor whiteColor];
        if ([string isEqualToString:seletedTag]) {
            style.backgroundColor = Color_gree;
        }
        style.shadowColor = [UIColor clearColor];
        style.borderWidth = 1;
        style.borderColor = Color_red;
        TTGTextTagStringContent *content = [TTGTextTagStringContent contentWithText:string];
        content.textFont = [UIFont systemFontOfSize:12];
        content.textColor = Color_red;
        TTGTextTag *textTag = [TTGTextTag tagWithContent:content style:style];
        [textTags addObject:textTag];
    }
    [_tagView addTags:textTags];
    _tagView.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 40;
    [_tagView reload];
}

- (void)setTags:(NSArray <NSString *> *)tags withHots:(NSArray *)seletedTags {
    [_tagView removeAllTags];

    NSMutableArray *textTags = [NSMutableArray new];
    for (NSString *string in tags) {
        
        TTGTextTagStyle *style = [TTGTextTagStyle new];
        style.extraSpace = CGSizeMake(5, 5);
        style.backgroundColor = [UIColor whiteColor];
        if (seletedTags.count > 0 && [seletedTags containsObject:string]) {
            style.backgroundColor = Color_gree;

        }
       
        style.shadowColor = [UIColor clearColor];
        style.borderWidth = 1;
        style.borderColor = Color_red;
        
        TTGTextTagStringContent *content = [TTGTextTagStringContent contentWithText:string];
        content.textFont = [UIFont systemFontOfSize:12];
        content.textColor = Color_red;
    
        TTGTextTag *textTag = [TTGTextTag tagWithContent:content style:style];
        [textTags addObject:textTag];
    }
    [_tagView addTags:textTags];

    // Use manual height, update preferredMaxLayoutWidth
    _tagView.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 40;

    [_tagView reload];
}

- (void)textTagCollectionView:(TTGTextTagCollectionView *)textTagCollectionView didTapTag:(TTGTextTag *)tag atIndex:(NSUInteger)index {
    
    HotGLVC *vc = [[HotGLVC alloc] init];
    vc.glName = tag.content.getContentAttributedString.string;
    [self.viewController.navigationController pushViewController:vc animated:YES];
        
}



@end
